set testenv=%1%
set level=%2%
set jobname=%3%
set module=%4%
set project=%5%
set build_num=%6%
if %testenv%==test (echo test环境 & copy /Y ..\settings\hosts\test\hosts C:\Windows\System32\drivers\etc\hosts)
if %testenv%==demo (echo demo环境 & copy /Y ..\settings\hosts\demo\hosts C:\Windows\System32\drivers\etc\hosts)
if %testenv%==product (echo demo环境 & copy /Y ..\settings\hosts\product\hosts C:\Windows\System32\drivers\etc\hosts)
if %testenv%==autotest (echo demo环境 & copy /Y ..\settings\hosts\autotest\hosts C:\Windows\System32\drivers\etc\hosts)
set timevar="%time:~0,2%"

if /i %timevar% LSS "10" (set time=%date:~0,4%%date:~5,2%%date:~8,2%0%time:~1,1%%time:~3,2%%time:~6,2%) else (set time=%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%)
set outputdir=E:\rfoutput\%jobname%\%testenv%\%build_num%
set tmpdir=%outputdir:\=Q_Q% 
set dir=%tmpdir::=C_C%

set outputdir_first=E:\rfoutput\%jobname%\%testenv%\%build_num%\run1
set tmpdir2=%outputdir_first:\=Q_Q% 
set dir2=%tmpdir2::=C_C%

set outputdir_fail=E:\rfoutput\%jobname%\%testenv%\%build_num%\runfail
set tmpdir3=%outputdir_fail:\=Q_Q% 
set dir3=%tmpdir3::=C_C%

set levelstr=-i %level%
if %level%==level2 (set levelstr=%levelstr%ORlevel1)
if %level%==level3 (set levelstr=%levelstr%ORlevel1ORlevel2)
if %level%==all (set levelstr=)
for /F %%i in ('mkvirtualenv %jobname%') do set list=%%i && workon %jobname% && cd ..\case\%project% && pip install -r requirements.txt && robot %levelstr%  -v testenv:%testenv% -v default_output_dir:%dir2% -E colon:C_C -E slash:Q_Q  -d %outputdir_first% --exclude=notrun %module% & robot %levelstr%  -v testenv:%testenv% -v default_output_dir:%dir3% -E colon:C_C -E slash:Q_Q  -R %outputdir_first%\output.xml  -d %outputdir_fail% --exclude=notrun %module% & rebot -d  %outputdir% -o  %outputdir%\output.xml  -R %outputdir_first%\output.xml %outputdir_fail%\output.xml & deactivate
